package com.alibaba.dingtalk.openapi.newmessage.delivery;/*/*/

import com.alibaba.dingtalk.openapi.exception.ApiRuleException;
import com.alibaba.dingtalk.openapi.newmessage.entity.Msg;
import com.alibaba.dingtalk.openapi.newmessage.utils.DeliveryCheckUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 发送普通消息
 * @author 魏荣杰
 * @date 2019/5/20 14:54
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class SendToConversationMsgDelivery extends AbstractDelivery {
    private static final long serialVersionUID = -3059898876428507447L;
    /**
     * 消息发送者 userId
     */
    private String sender;
    /**
     * 	群会话或者个人会话的id，通过JSAPI的dd.chooseChatForNormalMsg接口唤起联系人界面选择之后即可拿到会话cid
     */
    private String cid;
    /**
     * 消息内容，最长不超过2048个字节
     */
    private Msg msg;

    @Override
    public JSONObject toJsonObject() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sender", this.sender);
        jsonObject.put("cid", this.cid);
        jsonObject.put("msg", this.msg.toJsonObject());
        return jsonObject;
    }

    @Override
    public void check() throws ApiRuleException {
        DeliveryCheckUtils.checkNotEmpty(this.sender, "sender");
        DeliveryCheckUtils.checkNotEmpty(this.cid, "cid");
        DeliveryCheckUtils.checkNotEmpty(this.msg, "msg");
    }
}
